package edu.nazarevych.portal.entities;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Table;
import javax.persistence.Version;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.springframework.beans.factory.annotation.Configurable;

@Configurable
@Entity
@Table(name = "tbl_Station")
public class Stations extends BaseEntity {

	@Column(name = "Name")
	private String Name;

	@Column(name = "Longitude")
	private float Longitude;

	@Column(name = "Latitude")
	private float Latitude;

	@Column(name = "Address")
	private String Address;

	@Column(name = "Contacts")
	private String Contacts;

	@Column(name = "Info")
	private String Info;

	public String getName() {
		return Name;
	}

	public void setName(String name) {
		Name = name;
	}

	public float getLongitude() {
		return Longitude;
	}

	public void setLongitude(float longitude) {
		Longitude = longitude;
	}

	public float getLatitude() {
		return Latitude;
	}

	public void setLatitude(float latitude) {
		Latitude = latitude;
	}

	public String getAddress() {
		return Address;
	}

	public void setAddress(String address) {
		Address = address;
	}

	public String getContacts() {
		return Contacts;
	}

	public void setContacts(String contacts) {
		Contacts = contacts;
	}

	public String getInfo() {
		return Info;
	}

	public void setInfo(String info) {
		Info = info;
	}

	@PersistenceContext
	transient EntityManager entityManager;

	public static final EntityManager entityManager() {
		EntityManager em = new Stations().entityManager;
		if (em == null)
			throw new IllegalStateException(
					"Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)");
		return em;
	}

	public static long countStationses() {
		return entityManager().createQuery("SELECT COUNT(o) FROM Stations o",
				Long.class).getSingleResult();
	}

	public static List<Stations> findAllStationses() {
		return entityManager().createQuery("SELECT o FROM Stations o",
				Stations.class).getResultList();
	}

	public static Stations findStations(long id) {
		return entityManager().find(Stations.class, id);
	}

	public static List<Stations> findStationsEntries(int firstResult,
			int maxResults) {
		return entityManager()
				.createQuery("SELECT o FROM Stations o", Stations.class)
				.setFirstResult(firstResult).setMaxResults(maxResults)
				.getResultList();
	}

	@Column(name = "identifier")
	private String identifier;

	public String getIdentifier() {
		return identifier;
	}

	public void setIdentifier(String identifier) {
		this.identifier = identifier;
	}

	public String toString() {
		return ReflectionToStringBuilder.toString(this,
				ToStringStyle.SHORT_PREFIX_STYLE);
	}

}
